<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单打印 - #{{ order.order_number }}</title>
    <style>
        body {
            font-family: Arial, "Microsoft YaHei", sans-serif;
            font-size: 14px;
            line-height: 1.5;
            color: #333;
            max-width: 900px;
            margin: 0 auto;
            padding: 20px;
        }
        .print-header {
            text-align: center;
            margin-bottom: 20px;
            border-bottom: 2px solid #ddd;
            padding-bottom: 10px;
        }
        .shop-name {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 5px;
        }
        .print-title {
            font-size: 16px;
            color: #666;
        }
        .print-info {
            margin-bottom: 20px;
        }
        .info-group {
            display: flex;
            margin-bottom: 10px;
        }
        .info-label {
            font-weight: bold;
            width: 120px;
        }
        .info-content {
            flex: 1;
        }
        .print-items {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        .print-items th, .print-items td {
            border: 1px solid #ddd;
            padding: 8px 12px;
            text-align: left;
        }
        .print-items th {
            background-color: #f5f5f5;
        }
        .print-summary {
            display: flex;
            justify-content: flex-end;
            margin-bottom: 20px;
        }
        .print-total {
            width: 250px;
            border: 1px solid #ddd;
            padding: 10px 15px;
        }
        .print-total-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 5px;
        }
        .print-total-label {
            font-weight: bold;
        }
        .print-total-value {
            text-align: right;
        }
        .print-footer {
            text-align: center;
            font-size: 12px;
            color: #999;
            margin-top: 30px;
            border-top: 1px solid #eee;
            padding-top: 10px;
        }
        .print-remark {
            margin-bottom: 20px;
            padding: 10px;
            border: 1px dashed #ddd;
            background-color: #f9f9f9;
        }
        .subtotal {
            text-align: right;
        }
        .status-timeline {
            margin-bottom: 20px;
        }
        .timeline-item {
            display: flex;
            margin-bottom: 8px;
        }
        .timeline-date {
            width: 180px;
        }
        .timeline-content {
            flex: 1;
        }
        @media print {
            body {
                padding: 0;
                font-size: 12px;
            }
            .no-print {
                display: none;
            }
            .print-actions {
                display: none;
            }
        }
    </style>
</head>
<body>
    <div class="print-actions no-print" style="text-align: right; margin-bottom: 15px;">
        <button onclick="window.print();">打印订单</button>
        <button onclick="window.close();">关闭窗口</button>
    </div>

    <div class="print-header">
        <div class="shop-name">巧巧点餐系统</div>
        <div class="print-title">订单明细单 #{{ order.order_number }}</div>
    </div>

    <div class="print-info">
        <div class="info-group">
            <div class="info-label">订单号：</div>
            <div class="info-content">{{ order.order_number }}</div>
        </div>
        <div class="info-group">
            <div class="info-label">下单时间：</div>
            <div class="info-content">{{ order.created_at|date:"Y-m-d H:i:s" }}</div>
        </div>
        <div class="info-group">
            <div class="info-label">订单状态：</div>
            <div class="info-content">
                {% if order.status == 1 %}
                    待付款
                {% elif order.status == 2 %}
                    待发货
                {% elif order.status == 3 %}
                    待收货
                {% elif order.status == 4 %}
                    待评价
                {% elif order.status == 5 %}
                    已完成
                {% elif order.status == 6 %}
                    已取消
                {% endif %}
            </div>
        </div>
        {% if order.table_number %}
        <div class="info-group">
            <div class="info-label">桌号：</div>
            <div class="info-content">{{ order.table_number }}</div>
        </div>
        {% endif %}
        <div class="info-group">
            <div class="info-label">顾客：</div>
            <div class="info-content">{{ order.user.username }}</div>
        </div>
        {% if order.receiver %}
        <div class="info-group">
            <div class="info-label">收货人：</div>
            <div class="info-content">{{ order.receiver }}</div>
        </div>
        {% endif %}
        {% if order.receiver_phone %}
        <div class="info-group">
            <div class="info-label">联系电话：</div>
            <div class="info-content">{{ order.receiver_phone }}</div>
        </div>
        {% endif %}
        {% if order.address %}
        <div class="info-group">
            <div class="info-label">收货地址：</div>
            <div class="info-content">{{ order.address }}</div>
        </div>
        {% endif %}
    </div>

    {% if order.remark %}
    <div class="print-remark">
        <div style="font-weight: bold; margin-bottom: 5px;">订单备注：</div>
        <div>{{ order.remark|linebreaks }}</div>
    </div>
    {% endif %}

    <div class="status-timeline">
        <div style="font-weight: bold; margin-bottom: 8px;">订单时间线：</div>
        <div class="timeline-item">
            <div class="timeline-date">{{ order.created_at|date:"Y-m-d H:i:s" }}</div>
            <div class="timeline-content">订单创建</div>
        </div>
        
        {% if order.paid_at %}
        <div class="timeline-item">
            <div class="timeline-date">{{ order.paid_at|date:"Y-m-d H:i:s" }}</div>
            <div class="timeline-content">订单支付</div>
        </div>
        {% endif %}
        
        {% if order.delivered_at %}
        <div class="timeline-item">
            <div class="timeline-date">{{ order.delivered_at|date:"Y-m-d H:i:s" }}</div>
            <div class="timeline-content">订单发货</div>
        </div>
        {% endif %}
        
        {% if order.received_at %}
        <div class="timeline-item">
            <div class="timeline-date">{{ order.received_at|date:"Y-m-d H:i:s" }}</div>
            <div class="timeline-content">确认收货</div>
        </div>
        {% endif %}
        
        {% if order.finished_at %}
        <div class="timeline-item">
            <div class="timeline-date">{{ order.finished_at|date:"Y-m-d H:i:s" }}</div>
            <div class="timeline-content">订单完成</div>
        </div>
        {% endif %}
        
        {% if order.canceled_at %}
        <div class="timeline-item">
            <div class="timeline-date">{{ order.canceled_at|date:"Y-m-d H:i:s" }}</div>
            <div class="timeline-content">订单取消</div>
        </div>
        {% endif %}
    </div>

    <table class="print-items">
        <thead>
            <tr>
                <th width="10%">图片</th>
                <th width="40%">商品名称</th>
                <th width="15%">单价</th>
                <th width="15%">数量</th>
                <th width="20%">小计</th>
            </tr>
        </thead>
        <tbody>
            {% for item in order_items %}
            <tr>
                <td>
                    {% if item.food.image %}
                    <img src="{{ item.food.image.url }}" alt="{{ item.food.name }}" style="max-width: 50px; max-height: 50px;">
                    {% else %}
                    无图片
                    {% endif %}
                </td>
                <td>{{ item.food.name }}</td>
                <td>{{ item.food_price }} 亲亲币</td>
                <td>{{ item.count }}</td>
                <td class="subtotal">{{ item.total_price }} 亲亲币</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>

    <div class="print-summary">
        <div class="print-total">
            <div class="print-total-row">
                <div class="print-total-label">商品总额：</div>
                <div class="print-total-value">{{ order.total_price }} 亲亲币</div>
            </div>
            <div class="print-total-row">
                <div class="print-total-label">配送费用：</div>
                <div class="print-total-value">0.00 亲亲币</div>
            </div>
            <div class="print-total-row" style="margin-top: 10px; border-top: 1px solid #ddd; padding-top: 5px;">
                <div class="print-total-label">订单总计：</div>
                <div class="print-total-value"><strong>{{ order.total_price }} 亲亲币</strong></div>
            </div>
        </div>
    </div>

    <div class="print-footer">
        <p>感谢您的惠顾，欢迎再次光临！</p>
        <p>打印时间：{% now "Y-m-d H:i:s" %}</p>
    </div>
</body>
</html> 